#./utils/words.py -- Natural Language(Current English) Process: Words part.
#coding:utf-8


# Import Needs
import sys
import inspect
sys.path.append("..")
from constants import *


# Fuction: word_split()
def word_split(loggerset, para):
    """Function to split words

    Args:
        loggerset (Class:loggerseet): Class to log
        para (str): The paragraph to split into words

    Returns:
        list: The word's been split into.
    """    
    result = []
    loggerset.log("Spliting to word: "+para, level=DEBUG, ln=inspect.getframeinfo(inspect.currentframe()).lineno, filename=__file__)
    para_spllited = para.split(" ") # Split with blanks
    for i, j in enumerate(para_spllited): # Take 'words' successively
        found = None    # Define found var
        for punctuation in PUNCTUATIONS:    # Take punctuations successively
            if punctuation in j:    # Found punctuation in 'word'
                j_spllited = j.split(punctuation)   # Split 'word' with punctuation
                j_raw = "".join(j_spllited) # Join it with blank to remove the punctuation
                found = punctuation
        else:   # Loop ended
            if bool(found): # If found
                result.append(j_raw)    # Add this word
                result.append(found)  # Add this punctuation
            else:   # Not found
                result.append(j)    # Add this word
    return result
